# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

import os
import sys
from datetime import datetime

# make NodeGraphQt module available.
base_path = os.path.abspath('.')
root_path = os.path.split(base_path)[0]
sys.path.insert(0, root_path)

# required for the theme template.
sys.path.insert(0, os.path.abspath('_themes'))

import NodeGraphQt
from sphinxawesome_theme.postprocess import Icons

# -- Project information -----------------------------------------------------

project = 'NodeGraphQt'
author = NodeGraphQt.pkg_info.__author__
copyright = '{}, {}'.format(datetime.now().year, author)

# The full version, including alpha/beta/rc tags
release = '{}'.format(NodeGraphQt.VERSION)
# The short X.Y version
version = '{0}.{1}'.format(*NodeGraphQt.VERSION.split('.'))


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'autodocsumm',
    'sphinx.ext.autodoc',
    'sphinx.ext.autosectionlabel',
    'sphinx.ext.autosummary',
    'sphinx.ext.coverage',
    'sphinx.ext.graphviz',
    'sphinx.ext.inheritance_diagram',
    'sphinx.ext.intersphinx',
    'sphinx.ext.napoleon',
    # theme template related
    'sphinxawesome_theme'
]

intersphinx_mapping = {
    # 'python': ('https://docs.python.org/3', None),
    'PySide2': ('https://doc.qt.io/qtforpython/', None),
}

# inheritance diagram remapping.
inheritance_alias = {
    'NodeGraphQt.base.graph.NodeGraph': 'NodeGraphQt.NodeGraph',
    'NodeGraphQt.base.graph.SubGraph': 'NodeGraphQt.SubGraph',
    'NodeGraphQt.base.node.NodeObject': 'NodeGraphQt.NodeObject',
    'NodeGraphQt.base.port.Port': 'NodeGraphQt.Port',
    'NodeGraphQt.nodes.backdrop_node.BackdropNode': 'NodeGraphQt.BackdropNode',
    'NodeGraphQt.nodes.base_node.BaseNode': 'NodeGraphQt.BaseNode',
    'NodeGraphQt.nodes.base_node_circle.BaseNodeCircle': 'NodeGraphQt.BaseNodeCircle',
    'NodeGraphQt.nodes.group_node.GroupNode': 'NodeGraphQt.GroupNode',
}

# autodoc options.
autodoc_default_options = {
    'autosummary': True,
    'members': True,
    'member-order': 'bysource',
    'undoc-members': False,
}

# autosummary generate stubs.
autosummary_generate = True

# autosummary overwrite generated stubs files.
autosummary_generate_option = True

rst_prolog = '''
.. |version_str| replace:: v{0}
'''.format(release)

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', "_themes"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'monokai'


# -- Options for HTML output -------------------------------------------------

# If given, this must be the name of an image file (path relative to the
# configuration directory) that is the favicon of the docs.
# Modern browsers use this as the icon for tabs, windows and bookmarks.
# It should be a Windows-style icon file (.ico), which is 16x16 or 32x32
# pixels large. Default: None.
html_favicon = '_images/favicon.png'
html_logo = None

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.

html_theme = 'sphinxawesome_theme'
html_theme_path = ['_themes']
html_show_sourcelink = False
html_show_sphinx = False
html_context = {
    'display_github': True,
    'github_user': 'jchanvfx',
    'github_repo': 'NodeGraphQt',
    'github_version': "main",
    'conf_py_path': '/docs/',
    'source_suffix': '.rst',
}

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
html_title = 'NodeGraphQt'
html_permalinks_icon = (
    '<svg xmlns="http://www.w3.org/2000/svg" '
    'height="1em" width="1em" viewBox="0 0 24 24"'
    '>'
    '<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 '
    '5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 '
    '0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>'
    '</svg>'
)
html_theme_options = {
    'logo_light': '_images/favicon.png',
    'logo_dark': '_images/favicon.png',
    # 'main_nav_links': {
    #     'Releases': 'https://github.com/jchanvfx/NodeGraphQt/releases',
    # },
    'show_scrolltop': True,
    'show_prev_next': True,
    'awesome_external_links': True,
    'extra_header_link_icons': {
        "GitHub Repository": {
            "link": "https://github.com/jchanvfx/NodeGraphQt",
            "icon": (
                '<svg height="26px" style="margin-top:-2px;display:inline" '
                'viewBox="0 0 45 44" '
                'fill="currentColor" xmlns="http://www.w3.org/2000/svg">'
                '<path fill-rule="evenodd" clip-rule="evenodd" '
                'd="M22.477.927C10.485.927.76 10.65.76 22.647c0 9.596 6.223 17.736 '
                "14.853 20.608 1.087.2 1.483-.47 1.483-1.047 "
                "0-.516-.019-1.881-.03-3.693-6.04 "
                "1.312-7.315-2.912-7.315-2.912-.988-2.51-2.412-3.178-2.412-3.178-1.972-1.346.149-1.32.149-1.32 "  # noqa
                "2.18.154 3.327 2.24 3.327 2.24 1.937 3.318 5.084 2.36 6.321 "
                "1.803.197-1.403.759-2.36 "
                "1.379-2.903-4.823-.548-9.894-2.412-9.894-10.734 "
                "0-2.37.847-4.31 2.236-5.828-.224-.55-.969-2.759.214-5.748 0 0 "
                "1.822-.584 5.972 2.226 "
                "1.732-.482 3.59-.722 5.437-.732 1.845.01 3.703.25 5.437.732 "
                "4.147-2.81 5.967-2.226 "
                "5.967-2.226 1.185 2.99.44 5.198.217 5.748 1.392 1.517 2.232 3.457 "
                "2.232 5.828 0 "
                "8.344-5.078 10.18-9.916 10.717.779.67 1.474 1.996 1.474 4.021 0 "
                "2.904-.027 5.247-.027 "
                "5.96 0 .58.392 1.256 1.493 1.044C37.981 40.375 44.2 32.24 44.2 "
                '22.647c0-11.996-9.726-21.72-21.722-21.72" '
                'fill="currentColor"/></svg>'
            ),
        },
        "PyPI Package": {
            "link": "https://pypi.org/project/NodeGraphQt",
            "icon": (
                '<svg width="28px" height="28px" viewBox="0 0 20 20" '
                '<svg fill="currentColor" viewBox="0 0 24 24" '
                'xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" '
                'stroke-width="0"></g><g id="SVGRepo_tracerCarrier" '
                'stroke-linecap="round" stroke-linejoin="round"></g>'
                '<g id="SVGRepo_iconCarrier">'
                '<path d="M9.585 11.692h4.328s2.432.039 2.432-2.35V5.391S16.714'
                ' 3 11.936 3C7.362 3 7.647 4.983 7.647 4.983l.006 2.055h4.363v.'
                '617H5.92s-2.927-.332-2.927 4.282 2.555 4.45 2.555 4.45h1.524v-'
                '2.141s-.083-2.554 2.513-2.554zm-.056-5.74a.784.784 0 1 1 0-1.5'
                '7.784.784 0 1 1 0 1.57z"></path><path d="M18.452 7.532h-1.524v'
                '2.141s.083 2.554-2.513 2.554h-4.328s-2.432-.04-2.432 2.35v3.95'
                '1s-.369 2.391 4.409 2.391c4.573 0 4.288-1.983 4.288-1.983l-.00'
                '6-2.054h-4.363v-.617h6.097s2.927.332 2.927-4.282-2.555-4.451-2'
                '.555-4.451zm-3.981 10.436a.784.784 0 1 1 0 1.57.784.784 0 1 1 '
                '0-1.57z" /></path></g></svg>'
            )
        }
    }
}


# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static', '_images']
html_css_files = ['custom.css']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself.  Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.

html_sidebars = {
    '**': [
        'sidebar_main_nav_links.html',
        'sidebar_toc.html'
    ]
}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'NodeGraphQTdoc'


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
    (master_doc, 'nodegraphqt', 'NodeGraphQt Documentation',
     [author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (master_doc,
     'NodeGraphQt', 'NodeGraphQT Documentation',
     author,
     'NodeGraphQt',
     'Node graph framework that can be re-implemented into apps that supports PySide2.',
     'Miscellaneous'),
]

# -- Options for autodoc ----------------------------------------------------
autodoc_member_order = 'groupwise'

# -- Options for image link -------------------------------------------------
html_scaled_image_link = False
